package com.zjsru.oneDay202204;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author: likew
 * @Date: 2022/4/10
 *
 * 唯一摩尔斯密码词
 * 26个单词的摩斯密码
 * [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
 * 返回不同 单词翻译 的数量
 *
 * 输入: words = ["gin", "zen", "gig", "msg"]
 * 输出: 2
 * 解释:
 * 各单词翻译如下:
 * "gin" -> "--...-."
 * "zen" -> "--...-."
 * "gig" -> "--...--."
 * "msg" -> "--...--."
 *
 * 共有 2 种不同翻译, "--...-." 和 "--...--.".
 *
 *输入：words = ["a"]
 * 输出：1
 */
public class uniqueMorseRepresentations {
    String[] mos = new String[]{".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
    public int uniqueMorseRepresentations(String[] words) {
        Set<String> set = new HashSet<>();
        //获取第一个单词
        for (String s:words) {
            StringBuilder sb = new StringBuilder();
            //对单词的每个字母进行翻译
            for (char c:s.toCharArray()) {
                sb.append(mos[c - 'a']);
            }
            set.add(sb.toString());
        }
        return set.size();
    }
    
    public static void main(String[] args) {
        uniqueMorseRepresentations uniqueMorseRepresentations = new uniqueMorseRepresentations();
        String[] words = new String[]{"gin", "zen", "gig", "msg"};
        System.out.println(uniqueMorseRepresentations.uniqueMorseRepresentations(words));
    }
}
